//
//  UIBarButtonItem+Category.swift
//  mySwift
//
//  Created by 高赛 on 16/9/19.
//  Copyright © 2016年 高赛. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    // 如果在func前面加上class,就相当于OC中的+
    class func creatBarButtonItem(imageName: String, target: AnyObject?, action: Selector) -> UIBarButtonItem{
        let btn = UIButton()
        btn.setImage(UIImage(named: imageName), for: [])
        btn.setImage(UIImage(named: imageName + "_highlighted"), for: UIControlState.highlighted)
        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        btn.sizeToFit()
        return UIBarButtonItem(customView: btn)
    }
}
